// 模拟用户数据
const users = [
  {
    id: 1,
    username: 'admin',
    password: '123456',
    name: '管理员',
    avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
    role: 'admin'
  }
]

// 模拟延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

// 模拟登录接口
export const login = async (username: string, password: string) => {
  await delay(1000) // 模拟网络延迟
  const user = users.find(u => u.username === username && u.password === password)
  if (user) {
    const { password, ...rest } = user
    return {
      code: 200,
      data: {
        token: 'mock-token-' + Date.now(),
        user: rest
      },
      message: '登录成功'
    }
  }
  throw new Error('用户名或密码错误')
}

// 模拟获取用户信息接口
export const getUserInfo = async () => {
  await delay(500)
  return {
    code: 200,
    data: {
      id: 1,
      username: 'admin',
      name: '管理员',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
      role: 'admin'
    }
  }
}

// 模拟获取统计数据
export const getStats = async () => {
  await delay(500)
  return {
    code: 200,
    data: {
      totalUsers: Math.floor(Math.random() * 1000) + 500,
      activeUsers: Math.floor(Math.random() * 500) + 100,
      totalOrders: Math.floor(Math.random() * 2000) + 1000,
      pendingOrders: Math.floor(Math.random() * 100) + 10,
      revenue: Math.floor(Math.random() * 100000) + 50000,
    }
  }
}

// 模拟获取最近活动
export const getRecentActivities = async () => {
  await delay(500)
  const activities = [
    { id: 1, type: 'order', content: '新订单 #12345 已创建', timestamp: new Date().getTime() - 3600000 },
    { id: 2, type: 'user', content: '新用户注册: John Doe', timestamp: new Date().getTime() - 7200000 },
    { id: 3, type: 'system', content: '系统更新完成', timestamp: new Date().getTime() - 10800000 },
    { id: 4, type: 'order', content: '订单 #12344 已完成', timestamp: new Date().getTime() - 14400000 },
  ]
  return {
    code: 200,
    data: activities
  }
} 